package com.example.work4.http

import android.content.Context
import android.util.Log
import android.widget.Toast
import com.example.work4.common.FIN
import com.example.work4.http.body.po.PersonalInfoPage
import com.example.work4.http.imp.PersonRetrofit
import com.example.work4.po.ResultBean
import com.example.work4.po.SSOInfo
import com.example.work4.view.PersonalInfoDialog
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class PersonalInfoRetrofitImp {

    var context: Context?=null

    var retrofit = BaseRetrofit.get(FIN.BaseUrl)

    var mRetrofit = retrofit.create(PersonRetrofit::class.java)

    fun getPersonalInfo(id:Long){
        mRetrofit.getPersonalInfo(SSOInfo.token!!,id).enqueue(object :Callback<ResultBean<PersonalInfoPage>>{
            override fun onResponse(call: Call<ResultBean<PersonalInfoPage>>,
                                    response: Response<ResultBean<PersonalInfoPage>>) {
                if(response.code() == 200){
                    val pojo = response.body()?.data as PersonalInfoPage
                    PersonalInfoDialog.show(context!!,pojo)
                }
            }

            override fun onFailure(call: Call<ResultBean<PersonalInfoPage>>, t: Throwable) {
                Toast.makeText(context, "加载失败", Toast.LENGTH_SHORT).show();
            }

        })

    }

}